--- Tests mit von Daniel angemahnten Dingen

module examples.FunctionInstances where

class    PrintMulti r where prints :: String -> r
instance PrintMulti String where prints s = s 
instance (Show a, PrintMulti r) => PrintMulti (a -> r) where
    prints b = prints . (b ++) . show 
    -- prints b = prints . (show b ++)   


-- instance Show (a -> b)  where show _ = "function"

-- Funktion mit variabler Zahl von Argumenten, bei SO abgeschrieben
class    SumRes r       where sumOf :: Integer -> r
instance SumRes Integer where sumOf i = i

instance (Integral a, SumRes r) =>  SumRes  (a -> r) where
    sumOf x = sumOf • (x +) • toInteger

{- design für Strings mit Phantomtyp Char
type String = StringJ Char
data StringJ char = pure native java.lang.String where
    pure native itemAt frege.RT.itemAt :: StringJ a -> Int -> a  -- cheat!
    pure native literal new :: Prelude.String -> StringJ Char    -- for tests only
    pure native toString :: StringJ a -> Prelude.String          -- for tests only
    pure native length :: StringJ a -> Int
    pure native substring :: StringJ a -> Int -> Int -> StringJ a
    tail ss = substring ss 1 ss.length              -- für AbstractList
    -- pure native null :: StringJ a -> Bool

class    Head h       where head   :: h a -> a      -- fehlt noch in AbstractList
instance Head StringJ where head s  = s.itemAt 0
instance ListSource StringJ where 
    toList ss | "" <- ss.toString = []
              | otherwise = ss.head : toList ss.tail
-}

main _ = do 
    -- println id
    let x = prints "a" "b" "c" "d" :: String
    println x
    return ()
    
    -- println (sumOf 1n 2n 3n :: Integer)
    -- (println • head   • String.literal) "¿?"
    -- (println • toList • String.literal) "Cool"   